﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ProtoBuf;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
             const String PATH = "e://data.bin";  
            List<Test> testData = new List<Test>();
            for (int i = 0; i < 100; i++)
            {
                Test test=new Test();
                test.Id=i;
                test.data=new Dictionary<string,string>();
                test.data.Add("2",(i*2).ToString());
                test.data.Add("3",(i*3).ToString());
                test.data.Add("4",(i*4).ToString());
                test.data.Add("5",(i*5).ToString());

                testData.Add(test);
            }
            //将数据序列化后存入本地文件  
            using (Stream file = File.Create(PATH))
            {
                Serializer.Serialize<List<Test>>(file, testData);
                file.Close();
            }
            //将数据从文件中读取出来，反序列化  
            List<Test> fileData;
            using (Stream file = File.OpenRead(PATH))
            {
                fileData = Serializer.Deserialize<List<Test>>(file);
            }
            //打印数据  
            foreach (Test data in fileData)
            {
                Console.WriteLine(data.ToString());
            }
            Console.ReadKey();
        }
    }
}
